<!DOCTYPE html>
<html lang="en">

<head>
    <?php
    $title = [
        'title' => '登录'
    ];
    $this->load->view('/admin/common/header', $title);
    ?>
</head>

<body data-type="login" style="background-color: #e0dedc; position:absolute;height: 100%;width: 100%">
    <script src="assets/js/theme.js"></script>
    <div class="login_logo">
        <img src="/assets/img/logo.png">
    </div>
    <div class="content">
        <div class="login_boder">
                <h1>浙江爱思特采购系统</h1>
        </div>
        <div class="content_left">
        </div>
        <div class="content_center">
            <img src="/assets/img/content_center.png" class="content_bg">
            
            <!-- 登录界面 -->
            <form class="am-form " action="/admin/login/login" method="post">
                <div class="content_login">
                    <h3>用户登录</h3>
                <div class="input clearfix">
                    <div class="suo fl">
                        <img src="/assets/img/suo.png"/>
                    </div>
                    <div class="input2 fl">              
                        <div class="am-form-group am-u-sm-12">
                            <label for="user-name" class="am-u-sm-3 user-name">用户名</label>
                            <div class="am-u-sm-9">
                                <input type="text" class="" name="username" id="user-name">
                            </div>
                        </div>
                        <div class="am-form-group am-u-sm-12">
                            <label for="user-password" class="am-u-sm-3 user-password">密<span style="visibility: hidden;">一</span>码</label>
                            <div class="am-u-sm-9">
                                <input type="password" class="" name="password" id="user-password">
                            </div>
                        </div>
                    </div>
                </div>
                <input type="submit" class="button" value="登 录">
                    <div class="user-edit">
                        <a href="javascript:;" class="left" data-am-modal="{target: '#change-box', closeViaDimmer: 0, width: 580, height: 360}"><p>修改密码</p></a>
                        <a href="javascript:;" class="right"  data-am-modal="{target: '#tishi', closeViaDimmer: 0, width:350, height: 200}"><p>忘记密码？</p></a>
                    </div>
                </div>
            </form>
            <img src="/assets/img/content_bottom.png" class="content_bottom">
        </div>
        <div class="content_right"></div>
    </div>
    <div class="login_bottom">
        <img src="/assets/img/bottom.png">
    </div>
    <img src="/assets/img/bg_guang.png" class="bg_guang">

    <!-- 修改密码模态框 -->
    <div class="am-modal am-modal-no-btn" tabindex="-1" id="change-box">
      <div class="am-modal-dialog">
        <div class="am-modal-hd">修改密码
          <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd ">
            <form class="am-form am-u-md-12" data-am-validator style="padding: 0">
                <div class="am-g am-form-group">
                    <div class="am-u-md-12  am-u-sm-centered">
                        <label for="change-name" class="am-u-sm-2 am-form-label" style="line-height: 36px;">用户名:</label>
                        <div class="am-u-sm-6">
                          <input type="text" id="change-name" placeholder="" required>
                        </div>
                        <div class=" am-u-sm-4 " id="warn-name" style="line-height: 36px;">请输入用户名</div>
                    </div>
                </div>
                <div class="am-g am-form-group">
                    <div class="am-u-md-12  am-u-sm-centered">
                        <label for="old-password" class="am-u-sm-2 am-form-label" style="line-height: 36px;">原密码:</label>
                        <div class="am-u-sm-6">
                          <input type="password" id="old-password" placeholder="" required>
                        </div>
                        <div  class=" am-u-sm-4 " id="warn-old-password" style="line-height: 36px;">请输入原密码</div>
                    </div>
                </div>
                <div class="am-g am-form-group">
                    <div class="am-u-md-12  am-u-sm-centered">
                        <label for="new-password1" class="am-u-sm-2 am-form-label" style="line-height: 36px;">新密码:</label>
                        <div class="am-u-sm-6">
                          <input type="password" id="new-password1" placeholder="" required>
                        </div>
                        <div  class=" am-u-sm-4 " id="warn-new-password1" style="line-height: 36px;">请输入新密码</div>
                    </div>
                </div>
                <div class="am-g ">
                    <div class="am-u-md-12 am-form-group am-u-sm-centered">
                        <label for="new-password2" class="am-u-sm-2 am-form-label" style="line-height: 36px;">确认密码:</label>
                        <div class="am-u-sm-6">
                          <input type="password"  id="new-password2" placeholder="" required>
                        </div>
                        <div  class=" am-u-sm-4" id="warn-new-password2" style="line-height: 36px;">请确认新密码</div>
                    </div>
                </div>

                <div class="am-g">
                    <div class="am-u-md-10 am-form-group am-u-sm-centered" style="margin-top: 30px;">
                        <button type="button" class="am-btn am-btn-primary" style="margin-right: 30px;width: 100px;" id="change-password">修改密码</button>
                        <button type="button" class="am-btn am-btn-danger" style="width: 100px;" data-am-modal-close>取消</button>
                    </div>
                </div>
                
            </form>
        </div>
      </div>
    </div>
    
    <!-- 忘记密码模态框 -->
    <div class="am-modal am-modal-no-btn" tabindex="-1" id="tishi">
      <div class="am-modal-dialog">
        <div class="am-modal-hd">提示
          <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd ">
            忘记密码请联系管理员！
            <div class="am-g">
                <div class="am-u-md-10 am-form-group am-u-sm-centered" style="margin-top: 30px;">
                    <button type="button" class="am-btn am-btn-primary" style="margin-right: 30px;width: 100px;" data-am-modal-close>确定</button>
                    <button type="button" class="am-btn am-btn-danger" style="width: 100px;" data-am-modal-close>取消</button>
                </div>
            </div>
        </div>
      </div>
    </div>
    
    <script src="/assets/js/amazeui.min.js"></script>
    <script src="/assets/js/app.js"></script>
    <script>

        var verify1 = true;
        $("#change-name").blur(function(){
            var changeName = $(this).val();

            if(!$(this).val()){
                $("#warn-name").html("请输入用户名").css("color","red");
                verify1 = false;
            }else{
                $.ajax({
                    url:"/admin/login/issetUser",
                    data:{
                        username:changeName
                    },
                    dataType:"json",
                    type:"post",
                    success:function(data){
                        if(data.success){
                            $("#warn-name").html("成功").css("color","#797979");
                            verify1 = true;
                        }else{
                            $("#warn-name").html("用户名不存在").css("color","red");
                            verify1 = false;
                        }
                    },
                    error:function(error){
                        alert("请求出错");
                        
                    }
                });
            }
        });

        var verify2 = true;
        $("#old-password").blur(function(){
            if(!$(this).val()){
                $("#warn-old-password").html("请输入原密码").css("color","red");
                verify2 = false;
            }else{
                $("#warn-old-password").html("成功").css("color","#797979");
                verify2 = true;
            }
        });

        var verify3 = true;
        $("#new-password1").blur(function(){

            var oldPassword = $("#old-password").val();
            var password1 = $(this).val();

            if(!$(this).val()){
                $("#warn-new-password1").html("请输入新密码").css("color","red");
                verify3 = false;
            }else{

                if(oldPassword == password1){
                    $("#warn-new-password1").html("新旧密码不可一致").css("color","red");
                    verify = false;
                }else{
                    $("#warn-new-password1").html("成功").css("color","#797979");
                    verify = true;
                }
            }

        });

        var verify4 = true;
        $("#new-password2").blur(function(){

            var password1 = $("#new-password1").val();
            var password2 = $("#new-password2").val();

            if(!$(this).val()){
                $("#warn-new-password2").html("请输入新密码").css("color","red");
                verify4 = false;
            }else{
                if(password1 != password2){
                    $("#warn-new-password2").html("输入密码不一致").css("color","red");
                    verify4 = false;
                }else{
                    $("#warn-new-password2").html("成功").css("color","#797979");
                    verify = true;
                }
            }
        });

        $('#change-box').on('closed.modal.amui', function(){
            $("#change-name").val("");
            $("#old-password").val("");
            $("#new-password1").val("");
            $("#new-password2").val("");
            $("#warn-name").html("请输入用户名");
            $("#warn-old-password").html("请输入原密码");
            $("#warn-new-password1").html("请输入新密码");
            $("#warn-new-password2").html("请确认新密码");
        });

        var a = false;
        if(verify1 && verify2 && verify3 && verify4){
            a = true;
        }

        $("#change-password").on("click",function(){
            var changeName = $("#change-name").val();
            var oldPassword = $("#old-password").val();
            var password1 = $("#new-password1").val();

            if(a){
                $.ajax({
                    url:"/admin/login/editPassword",
                    data:{
                        username:changeName,
                        oldPassword:oldPassword,
                        newPassword:password1
                    },
                    dataType:"json",
                    type:"post",
                    async:false,
                    success:function(data){
                        var data = data.error ? data.error : data.success;
                        alert(data);
                        $("#change-box").modal('close');
                    },
                    error:function(error){
                        // console.log(data);
                        alert(error);
                        $("#change-box").modal('close');
                        
                    }
                });
            }else{
                alert("请正确输入信息。");
            }

        });
        
    </script>
</body>

</html>